-- card: 21375 from stack: in.3 -- bmap block id: 22059 -- flags: 4000 -- background id: 7836 -- name: PopList ----- HyperTalk script ----- on opencard global nextPos hide card field "source" set the scroll of card field "documentation" to 0 put 0 into nextPos pass opencard end opencard on Install get ChooseTargetStack() InstallResource XFCN,PopList,it end Install -- part 5 (field) -- low flags: 01 -- high flags: 2007 -- rect: left=18 top=32 right=288 bottom=480 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Documentation -- part 8 (field) -- low flags: 81 -- high flags: 0007 -- rect: left=18 top=31 right=289 bottom=492 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: source -- part 10 (button) -- low flags: 00 -- high flags: 8003 -- rect: left=304 top=299 right=321 bottom=425 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show C Source ----- HyperTalk script ----- on mouseUp get the visible of card field "source" set the visible of card field "source" to not it if it is false then set the name of me to "Hide C Source" else set the name of me to "Show C Source" end if end mouseUp -- part 11 (button) -- low flags: 00 -- high flags: 8004 -- rect: left=351 top=45 right=66 bottom=412 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: PopList ----- HyperTalk script ----- on mouseDown global mylast get the rect of me put item 2 of it into myTop put item 1 of it into myLeft get PopList("\one,two,three,\(-,\(disabled item,12345", myLeft,myTop,myLast) put it into myLast put "PopList choice was: "&mylast end mouseDown -- part contents for card part 5 ----- text ----- PopList 1.0d2 Roger Brown PopList is an XFCN that handles a pop-up menu. Menu items may contain Menu Manager meta-characters. Normally, those characters are not processed, so you can have menu items containing any text. If you want the meta-characters processed for an item, put a back slash "\" in the first character position. For example, in the item list of "a,b,(c", the third item will be the literal string "(c". In the list "a,b,\(c", the third item will be a disabled "c" because the "\" character tells the XFCN to process the "(" as a meta-character. Syntax is: get PopList(menuItems,left,top,default) where menuItems is an item list of items. Ex. "Chicago,Helvetica,Times" left and top are the left,top coordinates of the pop-up rectangle in local card coordinates default is an optional item number to indicate which item should be checked when the menu is first popped up returns the number of the item chosen or 0 if none was chosen. REVISION HISTORY 1.0d2 10/15/89 First public release. -- part contents for card part 8 ----- text ----- /* PopList1.0d2.c */ /* © Digital Medicine Inc. 1989 */ /* written in THINK C © Think Technologies, Inc */ /* by Roger Brown 10/15/89 */ /* version 1.0d2: ignore blank items unless they start with \" */ /* version 1.0d1: to process meta-characters, precede a menu item with a back slash "\" */ /* This is a HyperCard XFCN that handles popup menus. HyperCard Syntax is: PopList items,left,top,default ex. PopList "Chicago,Courier,Monaco,Times",100,100,1 returns: the number of the item chosen or 0 if none The menu is not remembered by the XCMD so the item list has to be passed each time. Meta characters are not processed unless a menu item starts with the \ character. The left,top position is in coordinates local to the card window. Parameters are menu item list, left and top coordinates of the default popup item, item number of the default popup item. To compile: create a project with this, ANSI-A4 and MacTraps. Build as code resource type XFCN named PopList. */ #include "MenuMgr.h" #include "HyperXCmd.h" #include "XCmdGlue.inc.c" #include "SetUpA4.h" #define FALSE 0 #define TRUE !FALSE #define NULL 0L char isNumber(); /* build a return result structure from a string */ ResultIs(paramPtr,theResult) XCmdBlockPtr paramPtr; char *theResult; { long len; Handle resultHandle; len = 1+strlen(theResult); resultHandle = NewHandle(len); BlockMove(theResult,*resultHandle,len); paramPtr->returnValue = resultHandle; } /* Get the number of HyperCard comma delimited items in string s. */ int NumHCItems(s) char *s; { int c,len,count,j; char temp[255]; long it; count = j = 0; len = strlen(s); for (c=0;cparamCount < 2) { ResultIs(paramPtr,"Not enough parameters in PopUp."); return; } /* lock down the parameters so we can point to them */ for (i=0;iparamCount;i++) { MoveHHi(paramPtr->params[i]); HLock (paramPtr->params[i]); } /* get parameters */ theItems = *(paramPtr->params[0]); strcpy(leftStr,*(paramPtr->params[1])); strcpy(topStr,*(paramPtr->params[2])); theDefault = 1; /* get the left,top */ if (!isNumber(leftStr,&theLeft)) { ResultIs(paramPtr,"Invalid Left parameter in popup"); for (i=0;iparamCount;i++) HUnlock (paramPtr->params[i]); return; } if (!isNumber(topStr,&theTop)) { ResultIs(paramPtr,"Invalid Top parameter in popup"); for (i=0;iparamCount;i++) HUnlock (paramPtr->params[i]); return; } if (paramPtr->paramCount > 3) { /* get the default */ strcpy(defaultStr,*(paramPtr->params[3])); if (!isNumber(defaultStr,&theDefault)) { ResultIs(paramPtr,"Invalid default number in popup"); for (i=0;iparamCount;i++) HUnlock (paramPtr->params[i]); return; } } /* get an id for this menu */ itsID = 0; while (itsID<128) itsID = UniqueID('MENU'); theMenu = NewMenu(itsID,"\pxxx"); /* create the menu */ InsertMenu(theMenu,-1); /* add it to the menu list */ /* add the items */ strcpy(itemStr,"\p "); /* create menu with 1 blank item cuz AppendMenu */ AppendMenu(theMenu,itemStr); /* can't handle a null string */ DelMenuItem(theMenu,1); /* now get rid of the blank menu item */ /* add all items by inserting - so we aren't constrained to 255 char limit */ itemCount = NumHCItems(theItems); realItem = 0; for (i=0;iparamCount;i++) HUnlock (paramPtr->params[i]); } /* XCMD entry point */ pascal void main(paramPtr) XCmdBlockPtr paramPtr; /* this is the entry point for the XFCN */ { RememberA0(); SetUpA4(); PopList(paramPtr); RestoreA4(); return; }